package indi.zhang.framework.tools;


import cn.dev33.satoken.stp.StpUtil;
import indi.zhang.framework.base.UserInfoForSession;
import indi.zhang.framework.constant.Constant;

/**
 * @author jy
 * @since 2021-11-02 13:28
 */
public class CurrentUserUtil {

	public static UserInfoForSession getCurrentUser() {
		return StpUtil.isLogin() ? (UserInfoForSession) StpUtil.getSession(false).get(Constant.USER) : null;
	}

	public static Long getUserId() {
		try {
			return StpUtil.getLoginIdAsLong();
		} catch (Exception e) {
			return 0L;
		}
	}

	public static String getName() {
		UserInfoForSession currentUser = getCurrentUser();
		return currentUser != null ? currentUser.getName() : null;
	}

}
